
/**
 * @param {*} captcha 图形验证码接口
 * @param {*} sendCode 手机验证码接口
 */
const NotifyService = require('../service/NotifyService')
const SecretTool = require('../utils/SecretTool')
const GetUserInfoTool = require('../utils/GetUserInfoTool')
const RandomTool = require('../utils/RandomTool')

const NotifyController = {
    captcha: async(req, res) => {
        const { type } = req.query;
        let _key = SecretTool.md5(GetUserInfoTool.getIp(req) + GetUserInfoTool.getUseragent(req))
        let handleRes = await NotifyService.captcha(_key, type)
        res.set('content-type', 'image/svg+xml')
        res.send(handleRes)
    },
    sendCode: async(req, res) => {
        const { phone, captcha, type } = req.body
        let _key = SecretTool.md5(GetUserInfoTool.getIp(req) + GetUserInfoTool.getUseragent(req))
        let handleRes = await NotifyService.sendCode(phone, captcha, type, _key, RandomTool.randomCode())
        console.log('handleRes: ', handleRes);
        res.send(handleRes)
    }
}
module.exports = NotifyController